"""
URL configuration for admin_learn_project project.

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/5.2/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path, include
from django.conf import settings
from django.conf.urls.static import static
from django.http import HttpResponse
from django.shortcuts import render
from .admin_sites import (
    super_admin_site, product_admin_site,
    order_admin_site, user_admin_site
)


def home_view(request):
    """首页视图，显示所有admin后台的入口"""
    context = {
        'admin_sites': [
            {
                'name': '默认Admin后台',
                'url': '/admin/',
                'description': 'Django默认的admin后台，包含所有功能',
                'color': 'primary'
            },
            {
                'name': '超级管理员后台',
                'url': '/super-admin/',
                'description': '最高权限的管理后台，包含数据统计和报表',
                'color': 'danger'
            },
            {
                'name': '产品管理后台',
                'url': '/product-admin/',
                'description': '专门管理产品、分类和品牌的后台',
                'color': 'success'
            },
            {
                'name': '订单管理后台',
                'url': '/order-admin/',
                'description': '专门处理订单和支付的后台',
                'color': 'warning'
            },
            {
                'name': '用户管理后台',
                'url': '/user-admin/',
                'description': '专门管理用户和权限的后台',
                'color': 'info'
            },
        ]
    }
    return render(request, 'home.html', context)


urlpatterns = [
    # 默认admin后台
    path('admin/', admin.site.urls),

    # 自定义admin后台
    path('super-admin/', super_admin_site.urls),
    path('product-admin/', product_admin_site.urls),
    path('order-admin/', order_admin_site.urls),
    path('user-admin/', user_admin_site.urls),

    # 首页
    path('', home_view, name='home'),
]

# 在开发环境中提供媒体文件服务
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
